package com.yuke.cloud.service.omc.controller.rpc;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yuke.cloud.common.base.dto.MsgNotificationBody;
import com.yuke.cloud.common.core.support.BaseController;
import com.yuke.cloud.common.util.wrapper.WrapMapper;
import com.yuke.cloud.common.util.wrapper.Wrapper;
import com.yuke.cloud.service.api.omc.dto.*;
import com.yuke.cloud.service.api.omc.service.OmcOrderFeignApi;
import com.yuke.cloud.service.api.opc.service.OpcSendNotifyFeignApi;
import com.yuke.cloud.service.api.uac.dto.UserInfoDto;
import com.yuke.cloud.service.api.uac.service.UacUserFeignApi;
import com.yuke.cloud.service.omc.controller.frontend.PayController;
import com.yuke.cloud.service.omc.controller.frontend.WxPayController;
import com.yuke.cloud.service.omc.dto.OdsTeamIntentDto;
import com.yuke.cloud.service.omc.entity.*;
import com.yuke.cloud.service.omc.mq.DelaySender;
import com.yuke.cloud.service.omc.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;


/**
 * Created by ssx on 2018/09/03.
 */
@Api(value = "API - OmcOrderFeignClient", tags = "处理OdsOrder相关请求的API", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@RestController
@RequestMapping
public class OmcOrderFeignClient extends BaseController implements OmcOrderFeignApi {
    @Resource
    private OdsOrderService odsOrderService;
    @Resource
    private OdsOrderGoodsService odsOrderGoodsService;
    @Resource
    private OdsOrderDeliveryService odsOrderDeliveryService;
    @Resource
    private PayController payController;
    @Resource
    private OdsPayOrderService odsPayOrderService;
    @Resource
    private UacUserFeignApi uacUserFeignApi;
    @Autowired
    private DelaySender delaySender;
    @Resource
    private OpcSendNotifyFeignApi opcSendNotifyFeignApi;
    @Resource
    private OdsTeamService odsTeamService;
    @Resource
    private OdsTeamGoodsService odsTeamGoodsService;
    @Resource
    private WxPayController wxPayController;
    @Resource
    private OdsAwardRecordService odsAwardRecordService;
    @Resource
    private OdsTeamIntentService odsTeamIntentService;

    @Override
    @ApiOperation(httpMethod = "GET", value = "分页获订单状态记录（全部，已付款，未付款，已取消，未取消,已退货）有记录")
    public Wrapper CountSales(@RequestBody String json) {

        JSONObject jsonObject = JSONObject.parseObject(json);
        String begintime1 = jsonObject.get("begintime").toString();
        String endtime1 = jsonObject.get("endtime").toString();
        String shopid = jsonObject.get("shopid").toString();
        Long longshopid = Long.valueOf(shopid);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date begintime = format.parse(begintime1);
            Date endtinme = format.parse(endtime1);
            List<OdsOrder> odslist = odsOrderService.countsales(begintime, endtinme, longshopid);
            System.out.println(odslist.get(0).getOrderSn());
            return WrapMapper.ok(odslist);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return WrapMapper.ok("查询错误");
    }

    //统计销售额
    @Override
    public Wrapper CountProductSalesbytime(@RequestBody String json) {

        JSONObject jsonObject = JSONObject.parseObject(json);
        String bywhat = jsonObject.get("bywhat").toString();
        String begintime1 = jsonObject.get("begintime").toString();
        String endtime1 = jsonObject.get("endtime").toString();
        String shopid = jsonObject.get("shopid").toString();
        Object productid = jsonObject.get("productid");
        Long longshopid = Long.valueOf(shopid);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        Date begintime = null;
        Date endtime = null;
        try {
            begintime = format.parse(begintime1);
            endtime = format.parse(endtime1);
            List<Map<String, Object>> odslist = odsOrderService.countProductsalesbytime(begintime, endtime, longshopid, productid, bywhat);
            return WrapMapper.ok(odslist);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return WrapMapper.ok("查询错误");
    }

    @Override
    public Object getit(@RequestParam("json") String json) {
        List<OdsOrder> finall = new ArrayList<>();
        if (json == null || json.equals("")) {
            return null;
        }
        Example example = new Example(OdsOrder.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("shippingStatus", 2);
        criteria.andEqualTo("orderType", 1);
        criteria.andEqualTo("userId", json);
        List list2 = new ArrayList();
        list2.add(2);
        list2.add(3);
        list2.add(4);
        list2.add(5);
        criteria.andNotIn("orderStatus", list2);
        List<OdsOrder> list = odsOrderService.selectByExample(example);
        if (list.size() == 0) {
            return null;
        }
        for (int i = 0; i < list.size(); i++) {
            OdsOrder odsOrder1 = list.get(i);
            Long orderId = odsOrder1.getOrderId();
            OdsOrderGoods odsOrderGoods = new OdsOrderGoods();
            odsOrderGoods.setOrderId(orderId);
            List<OdsOrderGoods> select = odsOrderGoodsService.select(odsOrderGoods);
            odsOrder1.setOdsgoods(select);
            finall.add(odsOrder1);
        }


        return finall;
    }

    //通过商品id获取当月全部销售量
    @Override
    public List<Map> countnum(@RequestBody List<Long> specIds) {
        List<Map> num = odsOrderGoodsService.countnum(specIds);
        System.out.println(num);
        List<Map> list = new ArrayList<>();
        Map map;
        if (num != null) {
            for (int i = 0; i < specIds.size(); i++) {
                boolean flag = true;
                for (int j = 0; j < num.size(); j++) {
                    if (specIds.get(i).toString().equals(num.get(j).get("specId").toString())) {
                        map = new HashMap();
                        map.put("specId", num.get(j).get("specId"));
                        map.put("nums", num.get(j).get("nums"));
                        list.add(map);
                        flag = false;
                    }
                }
                if (flag) {
                    map = new HashMap();
                    map.put("specId", specIds.get(i));
                    map.put("nums", 0);
                    list.add(map);
                }
            }
        } else {
            for (int i = 0; i < specIds.size(); i++) {
                map = new HashMap();
                map.put("specId", specIds.get(i));
                map.put("nums", 0);
                list.add(map);
            }

        }

        return list;
    }

    @Override
    public Wrapper getnum(OdsOrderDto id) {

        return null;
    }

    @Override
    public List<Map> gethistorynum(@RequestBody Map<String, List<Long>> niubi) {
        List<Map> list2 = odsOrderGoodsService.gethistorynum(niubi);
        List<Map> finalmap1 = new ArrayList<>();
        if (list2.size() == 0) {
            Long shopId = niubi.get("shopId").get(0);
            List<Long> list = niubi.get("specIds");
            for (int i = 0; i < list.size(); i++) {
                Map map = new HashMap();
                map.put("shopId", shopId);
                map.put("specId", list.get(i));
                map.put("nums", 0);
                finalmap1.add(map);
            }
            return finalmap1;
        }
        List<Map> finalmap = new ArrayList<>();
        Long shopId = niubi.get("shopId").get(0);
        List<Long> list = niubi.get("specIds");
        for (int i = 0; i < list.size(); i++) {
            Map map = new HashMap();
            map.put("shopId", shopId);
            map.put("specId", list.get(i));
            boolean flag = true;
            for (int j = 0; j < list2.size(); j++) {
                if (shopId.toString().equals(list2.get(j).get("shopId").toString()) && list.get(i).toString().equals(list2.get(j).get("specId").toString())) {
                    map.put("nums", list2.get(j).get("nums"));
                    flag = false;
                }
            }
            if (flag) {
                map.put("nums", 0);
            }
            finalmap.add(map);
        }


        return finalmap;
    }

    @Override
    public Object getorderinforbyorderid(@RequestParam("orderid") Long orderid) {
        OdsOrder byId = odsOrderService.findById(orderid);
        Long orderId = byId.getOrderId();
        OdsOrderGoods odsOrderGoods = new OdsOrderGoods();
        odsOrderGoods.setOrderId(orderId);
        List<OdsOrderGoods> select = odsOrderGoodsService.select(odsOrderGoods);
        byId.setGoodsList(select);
        return byId;

    }

    @Override
    public Long saveorderDeliver(@RequestBody Map map) {
        OdsOrderDelivery odsOrderDelivery = new OdsOrderDelivery();
        odsOrderDelivery.setOrderId(Long.valueOf(map.get("orderId").toString()));
        odsOrderDelivery.setTrackingNumber(map.get("TrackingNumber").toString());
        odsOrderDelivery.setExpressCompanyId(Long.valueOf(map.get("ExpressCompanyId").toString()));
        odsOrderDelivery.setSendTime(new Date());
        odsOrderDeliveryService.save(odsOrderDelivery);
        OdsOrder orderId = odsOrderService.findById(Long.valueOf(map.get("orderId").toString()));
        orderId.setShippingStatus((byte) 2);
        orderId.setSendTime(new Date());
        odsOrderService.update(orderId);
        DelayMq delayMq = new DelayMq();
        delayMq.setDelaytime(6 * 24 * 60 * 60);  // 6天后开始查询订单状态
//        delayMq.setDelaytime(5);  // todo 测试用 20190327
        delayMq.setOrderId(orderId.getOrderId());
        delayMq.setShippingType(orderId.getShippingType());  // add by wg 20190323
        delayMq.setSendTime(new Date());
        delaySender.sendDelay(delayMq);  // 开始查询物流状态
        return orderId.getUserId();
    }

    @Override
    //统计本月某个店铺某个商品的销售数量
    public List<GoodsInfo> countmonthnumbyprimikey(@RequestBody List<GoodsInfo> shop_goods_id) {
        List<Map> list = odsOrderGoodsService.countmonthnumbyprimikey(shop_goods_id);
        if (list == null) {
            for (int i = 0; i < shop_goods_id.size(); i++) {
                shop_goods_id.get(i).setCount(0);
            }
            return shop_goods_id;
        }
        System.out.println(list);
        System.out.println(list.size());
        Map map = list.get(0);
        if (map == null || map.size() == 0) {
            System.out.println("进来");
            for (int i = 0; i < shop_goods_id.size(); i++) {
                shop_goods_id.get(i).setCount(0);
            }
            return shop_goods_id;
        }


        for (int i = 0; i < shop_goods_id.size(); i++) {
            boolean flag = true;
            for (int j = 0; j < list.size(); j++) {
                if (shop_goods_id.get(i).getShopId().toString().equals(list.get(j).get("shop_id").toString()) && shop_goods_id.get(i).getProductId().toString().equals(list.get(j).get("spec_id").toString())) {
                    flag = false;
                    shop_goods_id.get(i).setCount(Integer.valueOf(list.get(j).get("goods_num").toString()));
                }
            }
            if (flag) {
                shop_goods_id.get(i).setCount(0);
            }

        }
        return shop_goods_id;
    }

    @Override
    public OdsOrderDto getbyid(@RequestParam(value = "orderid") Long orderid) {
        OdsOrder byId = odsOrderService.findById(orderid);
        OdsOrderDto odsOrderDto = new OdsOrderDto();
        BeanUtils.copyProperties(byId, odsOrderDto);
        return odsOrderDto;
    }

    @Override
    public int redund(@RequestBody Map map) {
        System.out.println(map);
        OdsOrder odsOrder = odsOrderService.findById(Long.valueOf(map.get("orderId").toString()));
        if (odsOrder == null) {
            return -1;
        }

        Long payId = 0L;

        OdsPayOrder odsPayOrder = null;
        if (odsOrder.getPayType() != 0) {
            Example example = new Example(OdsPayOrder.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andLike("orderIds", '%' + map.get("orderId").toString() + '%');
            List<OdsPayOrder> odsPayOrders = odsPayOrderService.selectByExample(example);
            if (odsPayOrders != null && odsPayOrders.size() > 0) {
                odsPayOrder = odsPayOrders.get(0);
                payId = odsPayOrders.get(0).getPayId();
            }
        }

//        System.out.println(payId);
        Object refund_amount = map.get("refund_amount");
        //map.put("orderId", orderId);

        int ret = 0;
        if (odsOrder.getPayType() == 2) {  // 支付宝原路退回
            double v = Double.parseDouble(refund_amount.toString());
            map.put("refund_amount", v / 100);
            map.put("out_trade_no", payId);
            JSONObject jsonObject = new JSONObject(map);
            System.out.println(jsonObject);
            ret = payController.orderPayRefund(jsonObject);
        } else if (odsOrder.getPayType() == 3) { // 微信原路退回
            map.put("refund_amount", Integer.valueOf(refund_amount.toString()));
            map.put("out_trade_no", payId);
            if (odsPayOrder != null && odsPayOrder.getAmountPaid() != null && odsPayOrder.getAmountPaid() > 0) {
                map.put("total_fee", odsPayOrder.getAmountPaid());
            } else {
                map.put("total_fee", odsOrder.getAmountPaid());
            }
            map.put("out_refund_no", map.get("goodsReturnId").toString());

            JSONObject jsonObject = new JSONObject(map);
            ret =  wxPayController.payback(jsonObject);
        } else if (odsOrder.getPayType() == 0 && odsOrder.getPayStatus() == 0) {  // add by wg 20190711 增加货到付款处理
            ret = 1;
        } else if (odsOrder.getPayType() == 0 && odsOrder.getPayStatus() == 1) {  // add by wg 20190711 增加货到付款处理
            ret = 0;  // 未知支付方式，无法在线退款
        }

        return ret;
    }

    @Override
    public List<OdsOrderDto> getbyidS(@RequestBody List<Long> orderids) {
        List<OdsOrderDto> back = new ArrayList<>();
        Example example = new Example(OdsOrder.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andIn("orderId", orderids);
        List<OdsOrder> list = odsOrderService.selectByExample(example);

        List<Long> list1 = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            list1.add(list.get(i).getUserId());
        }
        Wrapper<List<UserInfoDto>> userInfoByUserIds = uacUserFeignApi.getUserInfoByUserIds(list1);
        if (userInfoByUserIds == null || userInfoByUserIds.getResult() == null || userInfoByUserIds.getResult().size() == 0) {
            List<OdsOrderDto> back2 = new ArrayList<>();
            return back2;
        }
        List<UserInfoDto> result = userInfoByUserIds.getResult();
        for (int i = 0; i < list.size(); i++) {
            OdsOrderDto odsOrderDto = new OdsOrderDto();
            BeanUtils.copyProperties(list.get(i),odsOrderDto);
            for (int j = 0; j < result.size(); j++) {
                if (list.get(i).getUserId().toString().equals(result.get(j).getUserId().toString())) {

                    odsOrderDto.setUserId(result.get(j).getUserId());
                    odsOrderDto.setUserName(result.get(j).getUserName());
                    //odsOrderDto.setPayType(list.get(i).getPayType());
                    //odsOrderDto.setShopId(list.get(i).getShopId());
                    //odsOrderDto.setOrderId(list.get(i).getOrderId());
                    back.add(odsOrderDto);
                }
            }
        }

        return back;
    }

    @Override
    public int changetorefund(Long orderId, Double money) {
        OdsOrder byId = odsOrderService.findById(orderId);
        OdsOrder odsOrder = new OdsOrder();
        odsOrder.setOrderId(orderId);

        Integer amountPayable = byId.getAmountPayable();

        if (byId.getPayType() != 0) {
            //        odsOrder.setRefundMoney((int) (money * 100));
            odsOrder.setRefundMoney((int) (money * 1));
            if (amountPayable == (int) (money * 1)) {
                odsOrder.setOrderStatus((byte) 4);
            } else {
                odsOrder.setOrderStatus((byte) 5);
            }
        } else if (byId.getPayType() == 0 && byId.getPayStatus() == 0) {
            odsOrder.setRefundMoney(0);
            odsOrder.setOrderStatus((byte) 5);
        }

//        OdsOrder byId1 = odsOrderService.findById(orderId);
//        Integer amountPayable = byId1.getAmountPayable();

//        if (amountPayable == (int) (money * 100)) {

        // add by wg 20190712 修改其他状态
        odsOrder.setShippingStatus((byte)3);

        int update = odsOrderService.update(odsOrder);

        MsgNotificationBody msg = new MsgNotificationBody();
        msg.setTitle("退款通知");
        msg.setContent("您的订单" + byId.getOrderId() + "已经退款/退货成功");
        msg.setTime(new Date());
        msg.setReceiveType((byte) 1);
//        msg.setOrderType((byte) 1);
        msg.setMsgType("orderMsg");
        opcSendNotifyFeignApi.sendnotify(byId.getUserId().toString(), "退款/退货处理", JSON.toJSONString(msg), 1);
        opcSendNotifyFeignApi.sendnotify(byId.getUserId().toString(), "退款/退货处理", "您的订单" + byId.getOrderId() + "已经退款/退货成功", 0);
        return update;
    }

    @Override
    public Map getmapbyorderid(@RequestParam("orderId") Long aLong) {
        OdsOrderDelivery odsOrderDelivery = new OdsOrderDelivery();
        odsOrderDelivery.setOrderId(aLong);
        List<OdsOrderDelivery> select = odsOrderDeliveryService.select(odsOrderDelivery);
        if (select.size() == 0) {
            return new HashMap();
        }
        Long expressCompanyId = select.get(0).getExpressCompanyId();
        String trackingNumber = select.get(0).getTrackingNumber();

        Map map1 = new HashMap();
        map1.put("trackingNumber", trackingNumber);
//        map1.put("transferComponey", o);
        map1.put("transferComponey", expressCompanyId);

        // add by wg 20190328
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        map1.put("sendTime", sdf.format(select.get(0).getSendTime()));
        return map1;
    }

    @Override
    public Integer updateOrderGoods(@RequestBody OdsOrderGoodsDto odsOrderGoodsDto) {
        OdsOrderGoods odsOrderGoods = new OdsOrderGoods();
        BeanUtils.copyProperties(odsOrderGoodsDto,odsOrderGoods);
        System.out.println(odsOrderGoods);
        return odsOrderGoodsService.update(odsOrderGoods);
    }

    @Override
    public Integer updateOrderPay(@RequestBody OdsOrderDto odsOrderDto) {
        OdsOrder odsOrder = new OdsOrder();
        BeanUtils.copyProperties(odsOrderDto,odsOrder);
        return odsOrderService.update(odsOrder);
    }

    @Override
    public OdsOrderDto getOrderAndGoodsByOrderId(@RequestParam("orderId") Long orderId) {
        System.out.println("111111111orderId");
        if (orderId == null || orderId.equals(0)) {
            return null;
        }
        OdsOrderDto odsOrderDto = new OdsOrderDto();
        OdsOrder odsOrder = odsOrderService.findById(orderId);
        if (odsOrder == null) {
            return null;
        }
        BeanUtils.copyProperties(odsOrder, odsOrderDto);
        OdsOrderGoods odsOrderGoods = new OdsOrderGoods();
        odsOrderGoods.setOrderId(orderId);
        List<OdsOrderGoods> select = odsOrderGoodsService.select(odsOrderGoods);
        if (select == null || select.size() < 1) {
            return null;
        }
        List<OdsOrderGoodsDto> odsOrderGoodsDtoList = new ArrayList<>();
        for (OdsOrderGoods item : select) {
            OdsOrderGoodsDto odsOrderGoodsDto = new OdsOrderGoodsDto();
            BeanUtils.copyProperties(item, odsOrderGoodsDto);
            odsOrderGoodsDtoList.add(odsOrderGoodsDto);
        }
        odsOrderDto.setGoodList(odsOrderGoodsDtoList);
        return odsOrderDto;
    }


    @Override
    public List<OdsOrderApiDto> countByShopIds( @RequestBody List<Long> shopIdList,@RequestParam(value = "beginTime")String beginTime,@RequestParam(value = "endTime")String endTime) {
        List<OdsOrderApiDto> list = odsOrderService.countByShopIds(shopIdList,beginTime, endTime);
        return list;
    }


    @Override
    public Map countOrderByShopIds(@RequestBody List<Long> shopIds,@RequestParam("beginTime")  Date beginTime,@RequestParam("endTime")  Date endTime){
        Map map = odsOrderService.countOrderByShopIds(shopIds, beginTime, endTime);
        return map;
    }

    @Override
    public List<DmsStoreOrderApi> countByDmsStore(@RequestBody List<DmsStoreOrderApi> dmsStoreOrderApis) {
        List<DmsStoreOrderApi> list = odsOrderService.countByDmsStore(dmsStoreOrderApis);
        return list;
    }

    @Override
    public List<OdsTeamSpecInfoDto> selectTeamInfoBySpecIds(@RequestBody List<Long> specIds, @RequestParam("warehouseId") Long warehouseId) {
        List<OdsTeamSpecInfoDto> list = odsTeamService.selectTeamInfoBySpecIds(specIds,warehouseId);
        return list;
    }

    @Override
    public void sendAwardRecord(@RequestParam("orderId") Long orderId) {
        odsAwardRecordService.sendAwardRecord(orderId);
        return;
    }

    @Override
    public List<StoreOrderDto> countByShopListByStoreOrderDtos(@RequestBody List<StoreOrderDto> storeOrderDtos) {
        List<StoreOrderDto> list = odsOrderService.countByShopList(storeOrderDtos);
        return list;


    }

    /** 店主修改订单退货，wmc-AssGoodsReturnController-/batchReturn 调用
     * 结算修改后的订单，并提交数据，保存修改后的订单
     * @param odsOrderDto
     * @return
     */
    @Override
     public Wrapper<OdsOrderDto> countMoneyAndUpdate(@RequestBody OdsOrderDto odsOrderDto) {
         System.out.println("获得新订单重新计算后的真实数据,参数"+odsOrderDto);
         OdsOrder odsOrder = new OdsOrder();
         BeanUtils.copyProperties(odsOrderDto,odsOrder);
        List<OdsOrderGoods> goodsList = new ArrayList<>();

        for (OdsOrderGoodsDto goods : odsOrderDto.getGoodList()){
            OdsOrderGoods odsOrderGoods = new OdsOrderGoods();
            BeanUtils.copyProperties(goods,odsOrderGoods);
            goodsList.add(odsOrderGoods);
        }
        odsOrder.setGoodsList(goodsList);
        System.out.println("获得新订单重新计算后的真实数据,进入参数"+odsOrder);
         Wrapper<OdsOrder> wrapper = odsPayOrderService.getRealMoney(odsOrder);
         odsOrder = wrapper.getResult();
        System.out.println("获得新订单重新计算后的真实数据,gerRealMoney参数后："+odsOrder);
         if (odsOrder.getCouponReceiveId() != null && odsOrder.getCouponReceiveId() > 0) {

             Wrapper<OdsOrder> wrapperOrder = odsPayOrderService.doCouponCount(odsOrder);

             if (wrapperOrder.getCode() != 200) {
                 logger.info("wrapperOrder.getMessage()="+ wrapperOrder.getMessage());
                 //return WrapMapper.error(wrapperOrder.getMessage());
                 odsOrder.setCouponMoney(0);
             }
             odsOrder = wrapper.getResult();
             System.out.println("获得新订单重新计算后的真实数据,优惠券参数"+odsOrder);
         }

         //获得可用红包
         if (odsOrder.getRedReceiveId() != null && odsOrder.getRedReceiveId() > 0  && odsOrder.getRedMoney() != null) {
             Wrapper<OdsOrder> wrapperRed = odsPayOrderService.doRedCount(odsOrder);
             if (wrapperRed.getCode() != 200) {
                 logger.info("wrapperOrder.getMessage()=" + wrapperRed.getMessage());
                 //return WrapMapper.error(wrapperRed.getMessage());
                 odsOrder.setRedMoney(0);
             }
             odsOrder = wrapper.getResult();
             System.out.println("获得新订单重新计算后的真实数据,红包参数"+odsOrder);
         }


         odsOrderService.update(odsOrder);
        return WrapMapper.ok();
    }

    @Override
    public List<OdsGoodSalesApiDto> goodsSales(@RequestBody OdsGoodSalesApiDto odsGoodSalesApiDto) {
        List<OdsGoodSalesApiDto> list = odsOrderGoodsService.goodsSales(odsGoodSalesApiDto);
        return list;
    }

    /**
     * 统计团长开团接收的订单数
     * @param userId
     * @return
     */
    @Override
    public Integer countTeamIntentNumber(@RequestParam("userId") Long userId){

        return odsTeamIntentService.countTeamIntentNumber(userId);
    }


   @Override
    public Wrapper<List<OdsTeamSpecIntentDto>> selectTeamIntentByCondition(@RequestBody OdsTeamSpecIntentDto odsTeamSpecIntentDto) {
        OdsTeamIntentDto odsTeamIntentDto = new OdsTeamIntentDto();
        BeanUtils.copyProperties(odsTeamSpecIntentDto,odsTeamIntentDto);
        List<OdsTeamIntentDto> list = odsTeamIntentService.selectTeamIntentByCondition(odsTeamIntentDto);
        List<OdsTeamSpecIntentDto> odsTeamSpecIntentDtoList = new ArrayList<>();
        for (OdsTeamIntentDto item : list){
            OdsTeamSpecIntentDto odsTeamSpecIntentDto2 = new OdsTeamSpecIntentDto();
            BeanUtils.copyProperties(item,odsTeamSpecIntentDto2);
            odsTeamSpecIntentDtoList.add(odsTeamSpecIntentDto2);
        }
        return WrapMapper.ok(odsTeamSpecIntentDtoList);
    }

    @Override
    public Integer updateIntentGoods(@RequestBody OdsTeamSpecGoods odsTeamSpecGoods) {
        OdsTeamGoods odsTeamGoods = new OdsTeamGoods();
        BeanUtils.copyProperties(odsTeamSpecGoods,odsTeamGoods);
        System.out.println(odsTeamGoods);
        return odsTeamGoodsService.update(odsTeamGoods);
    }
}

